package com.avengers.mobile.layer.rest;





import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.avengers.mobile.layer.model.Cliente;
import com.avengers.mobile.layer.service.ClienteService;
import com.google.gson.Gson;


@Repository("restCliente")
@Path("/clients")
@Consumes({ MediaType.APPLICATION_JSON})
@Produces({ MediaType.APPLICATION_JSON })
public class ClienteRest {

	static final Log log = LogFactory.getLog(ClienteRest.class);
	
	@Autowired
	ClienteService clientService;
	
	Gson gson = new Gson();	
	
	@GET	
	public Response findClienteList() throws Exception{ 		
		return Response.ok(gson.toJson(clientService.findClienteList())).build();		
	}
	
	@Path("/{id}")
	@GET
	public Response find(@PathParam("id") int id) throws Exception{
		Cliente cliente = clientService.findClienteById(id);		
		if (cliente == null) {
			return Response.status(Status.INTERNAL_SERVER_ERROR).entity("El cliente no existe").build();
		}
		return Response.ok(gson.toJson(cliente)).build();		
	}
	
	
}



   